Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-29518: ContentType option "Default field for sorting children" has no effect on new created objects #2428

Merged
merged 5 commits into from
Sep 25, 2018

Conversation

mateuszbieniek
Copy link
Contributor

@mateuszbieniek mateuszbieniek commented Aug 23, 2018

Question Answer
JIRA issue EZP-29518
Bug yes
New feature no
Target version 6.7+
BC breaks no
Tests pass yes
Doc needed no

Setting ContentType option "Default field for sorting children" had no effect on newly created Content Object of said ContentType - they were always set to default "Content Name Ascending". This PR fixes it.

TODO:

  • Implement feature / fix a bug.
  • Implement/fix tests.
  • Ask for Code Review.

TODO ON MERGE

  • Adapt SiteAccessAware Repo when merging to 2.2

@mateuszbieniek
Copy link
Contributor Author

This is followup for #2421 as it got closed automatically after rebase.

@andrerom andrerom changed the title [WIP] EZP-29518: ContentType option "Default field for sorting children" has no effect on new created objects EZP-29518: ContentType option "Default field for sorting children" has no effect on new created objects Aug 23, 2018
@@ -80,16 +81,20 @@ public function setSession($id)
* Instantiates a new location create class.
*
* @param mixed $parentLocationId the parent under which the new location should be created
* @param ContentType|null $contentType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use FQCN (applies to other places in this PR as well).

@mateuszbieniek
Copy link
Contributor Author

Changes requested by @alongosz completed + additional code: missing failsafe for not implemented sort fields. Ping @andrerom, @konradoboza.

@@ -823,6 +824,14 @@ protected function buildSPILocationCreateStructs(array $locationCreateStructs)
);
}

if (!isset(Location::SORT_FIELD_MAP[$locationCreateStruct->sortField])) {
$locationCreateStruct->sortField = Location::SORT_FIELD_NAME;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would throw in this case, but that might be rather for kernel 8.x due to BC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, more of a 8.x way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failsafe for when someone set it to not implemented sortField - which did nothing prev this PR - and after updating will create the new object of said ContentType, which now would break.

@andrerom
Copy link
Contributor

@mateuszbieniek Could you fix the PHP 5 incompatibility here so we can send it to QA?
ref: PHP Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in /home/travis/build/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/ContentService.php on line 827

@mateuszbieniek
Copy link
Contributor Author

@andrerom done.

$properties['sortField'] = $contentType->defaultSortField;
$properties['sortOrder'] = $contentType->defaultSortOrder;
}
return new LocationCreateStruct($properties);
Copy link
Contributor

@andrerom andrerom Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, not a blocker for QA here but seems CS check for some reason did not spot this (cs/travis conf wrong on 6.7?)
Afaik our CS profile dictates a empty line before return statements, right @alongosz ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, indeed fixer should complain here. Locally it does.

@barbaragr barbaragr self-assigned this Sep 17, 2018
@barbaragr
Copy link

Tested with 1.7 seems OK, but I've got 2 questions:
Question 1:

  1. Clean installation of eZ Platform 2.2
  2. Create new Content Type named "Test Content Type", set Default field for sorting children to Location Priority and save it.
  3. Create a new Content Object of "Test Content Type" type. Publish it.
  4. Go to the "Details" tab of the newly created Content Object.
    Result: In "Sub-items sorting order" section you will see that sub-items are ordered by "Priority", but on the list when you can choose sorting ordering (on Details tab), there are only 4 items. When you create Content Type you can choose from 9 items. Article has got 5 items to select with.
    Content Type:

screen shot 2018-09-17 at 15 28 26

Test Content Type:

screen shot 2018-09-17 at 15 46 08

Article:

screen shot 2018-09-17 at 15 29 37

Do we accept those differences?

Question 2:

  1. Clean installation of eZ Platform 2.2
  2. Create new Content Type named "Test Content Type", set Default field for sorting children to Location Priority and save it.
  3. Create a new Content Object of "Test Content Type" type - "First". Publish it.
  4. Go to the "Details" tab of the newly created Content Object - sorting by Priority is set.
  5. Go to edit "Test Content Type" and change default sorting for Content Name and save it
  6. Create a new Content Object of "Test Content Type" type - "Second". Publish it.
  7. Go to the "Details" tab of the newly created Content Object - sorting by Name is set, but if you go back to the "First" content item, sorting by priority is still set. Shouldn't it be refreshed?

@mateuszbieniek
Copy link
Contributor Author

@barbaragr
1: this is out of the scope of this PR - not all sort fields that you can choose when editing/creating Content Type are implemented and even less are registered to be shown when selecting sort field for existing Content Object. I will create another PR that will fix that.

2: it should not be refreshed. Sorting field set in Content Type is a default one ONLY for newly created Content Object. Changing it changes sort field only for Content Objects that would be created afterward. This is the correct and expected behavior.

@lserwatka
Copy link
Member

@mateuszbieniek rebase is needed.

@mateuszbieniek
Copy link
Contributor Author

Done @lserwatka

@lserwatka lserwatka merged commit 73d0544 into ezsystems:6.7 Sep 25, 2018
@lserwatka
Copy link
Member

You can merge it up

@mateuszbieniek
Copy link
Contributor Author

@lserwatka done

@andrerom
Copy link
Contributor

Thanks for fixing this @mateuszbieniek, nice improvment of kernel 👍 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

6 participants